package com.ybwh.springboot1.common;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 响应base类
 */
@ApiModel(description="统一返回数据模型")
@Data
public class ReturnT<T> {
	
	public static final int SUCCEED_CODE = 1;

	public static final int FAIL_CODE = 0;
	
    
	 /**
     * ApiModelProperty()用于方法，字段 表示对model属性的说明或者数据操作更改
     * value–字段说明
     * name–重写属性名字
     * dataType–重写属性类型
     * required–是否必填
     * example–举例说明
     * hidden–隐藏
     */
	
	/**
     * 错误码
     */
    @ApiModelProperty(value="错误码")
    private int flag;

    /**
     * 错误描述
     */
    @ApiModelProperty(value="错误描述")
    private String error;

    /**
     * 返回数据
     */
    @ApiModelProperty(value="返回数据")
    private T resultMessage;


    public ReturnT() {

    }

    public ReturnT(int flag) {
        this.flag = flag;
    }

    public ReturnT(int flag, String error, T resultMessage) {
        this.flag = flag;
        this.error = error;
        this.resultMessage = resultMessage;
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
    
    public static <E> ReturnT<E> successResp(E resultMessage) {
    	return new ReturnT<E>(SUCCEED_CODE,null,resultMessage);
    }
    
    public static <E> ReturnT<E> failedResp(String msg) {
    	return new ReturnT<E>(FAIL_CODE,msg,null);
    }


}